package com.yuanfeng.action.front.buy.web;

import javax.servlet.http.HttpServletRequest;
import com.opensymphony.xwork2.ActionSupport;
import com.yuanfeng.action.front.buy.service.BookSearchService;
import com.yuanfeng.pojo.Books;
import org.apache.struts2.ServletActionContext;

public class BookSearchAction extends ActionSupport {

	/**
	 * 图书搜索的简单业务逻辑模块
	 */
	private BookSearchService bookSearchServiceImpl ;

	public void setBookSearchServiceImpl(BookSearchService bookSearchServiceImpl) {
		this.bookSearchServiceImpl = bookSearchServiceImpl;
	}

	/**
	 * 查询书籍
	 * @return
	 */
	public  String query() {
		HttpServletRequest request = ServletActionContext.getRequest();
		//得到书名
		String bookName = request.getParameter("bookName");
		if(bookName == null){
			return INPUT;
		}
		System.out.println(bookName);
			Books book = bookSearchServiceImpl.searchBook(bookName);
			if(book == null) {
				//为空查询无此图书
				request.setAttribute("result","failed");
				return "noBook";
			}else {
				//查询成功，即将转发
				request.setAttribute("book",book);
				return "bookDetail";
			}

		}

}
